<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('码盘管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="gysmc" name="gysmc" placeholder="供应商名称"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">ASN编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="asnbh" name="asnbh" placeholder="ASN编号"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">PO编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="dycgdbh" name="dycgdbh" placeholder="关联PO编号"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="time" id="createTime" placeholder="">
                        </div>
                    </div>



                        <!--<div class="layui-inline">-->
                            <!--<label class="layui-form-label">打印时间</label>-->
                            <!--<div class="layui-input-inline">-->
                                <!--<input type="text" class="layui-input" id="dysj" name="dysj_start" placeholder="yyyy-MM-dd HH:mm:ss"/>-->
                            <!--</div>-->

                        <!--</div>-->

                        <div class="layui-inline">
                            <label class="layui-form-label">码盘状态</label>

                            <!--<select name="mpzt" id="mpSelect" lay-search>-->
                            <!--</select>-->

                            <select name="mpzt" lay-filter="aihao">
                                <option value=""></option>
                                <option value="">全部</option>
                                <option value="0">未码盘</option>
                                <option value="1">已码盘</option>
                            </select>
                        </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">打印状态</label>

                            <select name="dy" lay-filter="aihao">
                                <option value=""></option>
                                <option value="">全部</option>
                                <option value="0">未打印</option>
                                <option value="1">已打印</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" onclick="queryTable(1)" id="query" data-type="reload">搜索</a>
                        <button type="reset" onclick="queryTable(0)" class="layui-btn layui-btn-normal">重置</button>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                aria-haspopup="true" aria-expanded="false">
                            多选操作 <span class="caret"></span>
                        </button>

                    </div>

                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
        <!--编辑用的-->
        <div id="bjEdit" style="display: none">
            <div class="layui-form-item">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="formEdit">
                    <div>&nbsp;</div>
                    <div class="layui-inline">
                        <label class="layui-form-label">ASN编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="asnbhId" name="asnbh" disabled="disabled"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">预计到货时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="stime" id="stimeId"
                                   placeholder="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">优先级</label>
                        <select id="yxjId" lay-filter="selFilter" disabled="disabled">
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">ASN类型</label>
                        <div class="layui-input-inline">
                            <select lay-ignore="lay-ignore" class="js-data-example-ajax" id="asnlxId"
                                    disabled="disabled"
                                    name="asnlx" select2 style="width: 193px"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">供应商编号</label>
                        <div class="layui-input-inline">
                            <select lay-ignore="lay-ignore" class="js-data-example-ajax" id="gysIds" disabled="disabled"
                                    name="gysid" select2 style="width: 193px"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">审核状态</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="shztId" name="shzt" disabled="disabled"/>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script th:inline="javascript">
    $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
    });
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'form', 'jquery', 'laydate', 'tablebutton'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        laydate.render({
            elem: '#stimeId'
            , theme: '#20a0ff'
            , range: '~'//练起来
        });

        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                //查询
                searchEvent: function () {
                    zzpUtils.refreshTable("#table");
                },
                /*码盘*/
                getEvent: function (data) {

                    if (data.row != undefined) {
                        upDialog(data.row.id);
                    }
                },
                /*明细*/
                searchSeparatedDetailEvent: function (data) {
                    if (data.row != undefined) {
                        mxDialog(data.row.id);
                    }
                },

                /*取消码盘*/
                confirmEvent: function (data) {
                    if (data.row != undefined) {
                        editDialog(data.row.id);
                    }
                },
                //打印
                printEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        printDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            printDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //多选取消码盘
                cancelBh: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        cancelDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            cancelDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }

                },

            }
        });
        //初始化
        zzpUtils.webSocket.init();

        //码盘操作
        function upDialog(id) {
             // alert(id);
            var ids=[];
            ids.push(id);
            zzpUtils.confirm("您将对选择的订单进行码盘", function (index) {
                zzpUtils.action({
                    url: "/wmspalletsorting/add",
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                });
            });
        }
        // 明细查询码盘后数据明细
        function mxDialog(id) {
            zzpUtils.dialog({
                title: "",
                type: 2,
                content: "/inOperation/mapan/detailMapan?id=" + id,
                area: ['90%', '75%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
        //取消码盘
        // function editDialog(id) {
        //     zzpUtils.dialog({
        //         title: "确认收货",
        //         type: 2,
        //         content: "/mpsh/qrMpsh?id=" + id,
        //         area: ['93%', '93%'], //设置dialog大小，也可以不设置，
        //         end: function () {//修改成功后刷新
        //             zzpUtils.refreshTable("#table");
        //         }
        //     });
        // }
        //右侧取消码盘按钮
        function editDialog(id) {
            // alert(id)
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("您将选择的码盘信息进行取消码盘的操作!", function (index) {
                zzpUtils.action({
                    url: "/wmspalletsorting/delete",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }
        //多选取消码盘
        function cancelDialog(ids) {

            var Ids = {ids: ids};
            $.ajax({
                url: '/zxsswms/wmspalletsorting/delete',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(Ids),
                success: function (data) {
                    if(data.type === 'success') {
                        layer.msg(data.title);
                        $('#table').bootstrapTable('refresh');
                    } else {
                        layer.msg(data.title);
                    }
                }
            })
        }


        //查看码盘明细
        function mxDialog(id) {
            // alert(id);
            zzpUtils.dialog({
                title: "",
                type: 2,
                content: "/inOperation/mapan/detailMapan?id=" + id,
                area: ['90%', '75%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }


        /*右侧打印*/
        function printDialog(ids){
            // alert(ids);
            zzpUtils.confirm("您将打印码盘信息", function (index) {
                zzpUtils.action({
                    url: "/wmspalletsorting/dySelecttp" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        if(data.title=='码盘信息打印失败'){
                            setTimeout(function () {
                                layer.msg(data.message);
                            }, 500);
                        }else{
                            var LODOP=getLodop();
                            LODOP.PRINT_INIT('打印码盘信息');
                            for(var i=0;i<data.rows.length;i++){
                                var oDate = new Date(); //实例一个时间对象；
                                var time=oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate()+' '+oDate.getHours()+':'+oDate.getMinutes()+':'+oDate.getSeconds();
                                LODOP.ADD_PRINT_TEXT(28,34,270,30,time);
                                LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                                LODOP.ADD_PRINT_BARCODE(48,34,270,47,"EAN128B",data.rows[i].asnbh);
                                LODOP.ADD_PRINT_TEXT(110,34,100,30,"货品编号");
                                LODOP.ADD_PRINT_TEXT(110,100,307,30,data.rows[i].bh);
                                LODOP.ADD_PRINT_TEXT(140,34,100,30,"货品名称");
                                LODOP.ADD_PRINT_TEXT(140,100,307,30,data.rows[i].mc);
                                LODOP.ADD_PRINT_TEXT(170,34,100,30,"供应商");
                                LODOP.ADD_PRINT_TEXT(170,100,307,30,data.rows[i].gys);
                                LODOP.ADD_PRINT_TEXT(200,34,100,30,"生产日期");
                                LODOP.ADD_PRINT_TEXT(200,100,307,30,data.rows[i].scrq);
                                LODOP.ADD_PRINT_BARCODE(210,180,190,40,"EAN128B",data.rows[i].lpn);
                                LODOP.ADD_PRINT_TEXT(255,34,307,30,"货品批号");
                                LODOP.ADD_PRINT_TEXT(255,100,307,30,data.rows[i].hppc);
                                if(i>=0){
                                    LODOP.NewPage();//分页
                                }
                            }
                        }
                        LODOP.PREVIEW();
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        };



        //查询字典表中的数据 码盘状态
        zzpUtils.select({
            elem:"#mpSelect",    //dom
            url:"/sysdictionary/getSysdictionary/wms_estimated_arrival_order_mpzt"
            //路径 以"/"开头，后边正常字典路径
        });
        //查询字典表中的数据 打印状态
        zzpUtils.select({
            elem:"#dySelect",    //dom
            url:"/sysdictionary/getSysdictionary/wms_estimated_arrival_show_dyzt"
            //路径 以"/"开头，后边正常字典路径
        });
        laydate.render({
            elem: '#stime'
            , theme: '#20a0ff'
        });

        //创建时间
        laydate.render({
            elem: '#createTime'
            ,range: true
        });
        laydate.render({
            elem: '#etime'
            , theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            pagination: true,
            url: '/wmspalletsorting/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'ckmc',
                title: '仓库'
            }, {
                field: 'hzmc',
                title: '货主'
            }, {
                field: 'asnbh',
                title: 'ASN编号'
            },{
                field: 'asnlx',
                title: 'ASN类型'
            },{
                field: 'show_asnzt',
                title: 'ASN状态'
            }, {
                field: 'yxj',
                title: '优先级',
                visible:false
            },{
                field: 'yjdhsjks',
                title: '预计到货开始'
            },{
                field: 'yjdhsjjs',
                title: '预计到货结束'
            },{
                field: 'cjsj',
                title: '创建时间'
            },{
                field: 'show_shzt',
                title: '审核状态'
            },{
                field: 'zdr',
                title: '制单人',
                visible:false
            },{
                field: 'ddshr',
                title: '审核人',
                visible:false
            },{
                field: 'show_dyzt',
                title: '打印状态',
                visible:false
            },{
                field: 'gysmc',
                title: '供应商名称'
            },{
                field: 'show_mpzt',
                title: '码盘状态'
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },

            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter
        });

        /*表格右侧按钮*/
  /*      function operateFormatter(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.mpzt == '0' && row.asnzt==0 && row.shzt==1) {

                    if (functions.tableBtn[i].name == '码盘'|| functions.tableBtn[i].name == '打印托盘码' ) {
                        button += btn;
                    }
                } else if (row.mpzt == '1') {//
                    if (functions.tableBtn[i].name == '码盘明细' || functions.tableBtn[i].name == '取消码盘' || functions.tableBtn[i].name == '打印托盘码') {
                        button += btn;
                    }
                } else if (row.mpzt == '2' ){
                    if (functions.tableBtn[i].name == '打印托盘码' ) {
                        button += btn;
                    }
                }
            }
            button += '</span>'
                + '</div>';
            return button;
        }
*/

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var button = '', buttons1 = '', buttons2 = '';
            var buttons = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var btn = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (item.event === 'printEvent' ) {
                    buttons1 += '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                } else {
                    if (row.mpzt == '0') {
                        if (functions.tableBtn[i].name == '码盘') {
                            buttons2 += btn;
                        }
                    } else if (row.mpzt == '1') {//部分收货
                        if (functions.tableBtn[i].name == '码盘明细' || functions.tableBtn[i].name == '取消码盘' ) {
                            buttons2 += btn;
                        }
                    }
                }
            }
            button += buttons1;
            button += buttons;
            button += buttons2;
            button += '</span>'
                + '</div>';
            return button;
        }

        //查询
        /* $(".inline-search-btn").on('click', function () {
             zzpUtils.refreshTable("#table");
         })*/


        //搜索按钮
        window.queryTable = function (val) {
            var formdata = $("form").serializeArray();
            var Datas = {};
            var cjsjstart = '',cjsjend = '';
            formdata.forEach(function (item) {
                Datas[item.name] = item.value;
            });
            if (Datas.time) {
                var start = Datas.time.substring(0, 10);
                var end = Datas.time.substring(12);
                var timestart = new Date(start);
                cjsjstart = timestart.getTime();
                var timeend = new Date(end);
                cjsjend = timeend.getTime();
            }
            var DATA = {};
            for (var key in Datas) {
                if(key !== 'time') {
                    if (val === 1) {
                        DATA[key] = Datas[key];
                    }else {
                        DATA[key] = "";
                    }
                }
            }


            if (Datas.time) {
                var start = Datas.time.substring(0, 10);
                var end = Datas.time.substring(12);
                var timestart = new Date(start);
                var timeend = new Date(end);
            }
            if (val === 1) {
                DATA.cjsj_start = cjsjstart;
                DATA.cjsj_end = cjsjend;
            }else {
                DATA.cjsj_start = "";
                DATA.cjsj_end = "";
            }
            DATA.page = 1;
            DATA.rows = 10;
            $('#table').bootstrapTable('refresh',{
                query: DATA
            })
        }

    });


</script>
</html>